﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CloudAppMonitor.Library;
using CloudAppMonitor.Data;

namespace CloudAppMonitor
{
    internal partial class CounterProperties : Form
    {
        MonitoredPerformanceCounter _performanceCounter;
        SqlStorage _storage;

        public CounterProperties(MonitoredPerformanceCounter performanceCounter, SqlStorage storage)
        {
            InitializeComponent();

            _performanceCounter = performanceCounter;
            _storage = storage;

            LoadValues();
        }

        private void LoadValues()
        {
            RoleInstance roleInstance = (from ri in _storage.RoleInstances
                                         where ri.RoleInstanceId == _performanceCounter.RoleInstanceId
                                         select ri).First();

            DeploymentName.Text = roleInstance.Role.Deployment.DeploymentName;
            RoleName.Text = roleInstance.Role.RoleName;
            RoleInstanceName.Text = roleInstance.RoleInstanceName;
            CounterName.Text = _performanceCounter.CounterName;

            CounterScale.Text = string.Format("{0:0.########}", _performanceCounter.Scale);
            CounterColor.Text = _performanceCounter.StyleColor.Name;
        }

        private void Ok_Click(object sender, EventArgs e)
        {
            _performanceCounter.Scale = float.Parse(CounterScale.Text);
            _performanceCounter.StyleColor = Color.FromName(CounterColor.Text);
        }
    }
}
